package com.yyys.web.controller;

import com.yyys.web.json.DRDailyRecommendJson;
import com.yyys.web.json.DRGoods;
import com.yyys.web.service.DRGoodsInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhengsenwen on 2017/8/19.
 */

@RestController
@RequestMapping("/goods")
public class GoodsController {
    private static Logger logger = Logger.getLogger(GoodsController.class);

    @Autowired
    private DRGoodsInfoService drGoodsInfoService;


    /**
     * 获取今天某餐厅此时（早餐、午餐、晚餐）的菜品  diningroom.html/ajax
     *
     * @param model
     * @param drId
     * @return
     */
    @RequestMapping(value = "/drGoodsInfo/{drId}", method = RequestMethod.GET)
    public List<DRGoods> getTodayDRGoodsInfo(Model model, @PathVariable Integer drId) {
        List<DRGoods> drGoodsList = new ArrayList<>();
        try {
            drGoodsList = drGoodsInfoService.getByDateDRClassAndCBName(drId);
        } catch (Exception e) {
            logger.info("getTodayDRGoodsInfo:" + e.getMessage());
            e.printStackTrace();
        }
        return drGoodsList;
    }

//    /**
//     * 获取今天某餐厅此时（早餐、午餐、晚餐）的菜品  diningroom.html/ajax
//     *
//     * @param drId
//     * @return
//     */
//    @RequestMapping(value = "/test/drGoodsInfo/{drId}", method = RequestMethod.GET)
//    public List<Object[]> getTodayDRGoodsInfo(@PathVariable Integer drId) {
//        List<Object[]> drGoodsList = new ArrayList<>();
//        try {
//            drGoodsList = drGoodsRepository.findByDateDRClassAndCBName("2017-08-29", drId, "副食", "晚餐");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return drGoodsList;
//    }


    /**
     * 获取今天某餐厅的推荐菜品    diningroom.html/banner/   ajax
     *
     * @param drId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/daily/recommend/{drId}")
    public List<DRDailyRecommendJson> getDailyRecommend(@PathVariable Integer drId) {
        List<DRDailyRecommendJson> drDailyRecommendJsonList = new ArrayList<>();
        try {
            drDailyRecommendJsonList = drGoodsInfoService.getDailyRecommend(drId);
        } catch (Exception e) {
            logger.info("getDailyRecommend:" + e.getMessage());
            e.printStackTrace();
        }
        return drDailyRecommendJsonList;
    }

//    /**
//     * 获取今天某餐厅的推荐菜品    diningroom.html/banner/   ajax
//     *
//     * @param drId
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping(value = "/test/daily/recommend/{drId}")
//    public List<Object[]> getDailyRecommend(Model model, @PathVariable Integer drId) {
//        List<Object[]> drDailyRecommendJsonList = new ArrayList<>();
//        try {
//            drDailyRecommendJsonList = drGoodsRepository.findDailyRecommendByQRAndDRID("2017-08-29", drId, "1");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return drDailyRecommendJsonList;
//    }

}
